package com.ark.frigate.redis.utils;

import java.io.Serializable;

import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.StringUtils;

import com.sun.org.apache.xerces.internal.impl.dv.util.HexBin;

/**
 * 占空间一点
 *
 * @Author ZengWeiLong
 * @Description Copy Right Beyonca
 * @Date 2022/7/14 13:35
 * @Version 1.0
 */
public class HexBinSerializer {

    public static <T> String serialize(T t) {
        if (t != null) {
            try {
                byte[] bytes = SerializationUtils.serialize((Serializable) t);
                return HexBin.encode(bytes);
            } catch (Exception e) {
                e.getMessage();
            }
        }
        return null;
    }

    public static <T> T deserialize(String objectString) {
        if (StringUtils.isNotBlank(objectString)) {
            try {
                byte[] decode = HexBin.decode(objectString);
                return SerializationUtils.deserialize(decode);
            } catch (Exception e) {
                e.getMessage();
            }
        }
        return null;
    }
}
